package biznussoft.fieldservice360;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentTransaction;
import biznussoft.fieldservice360.fragments.AccountsdetailsFragment;
import biznussoft.fieldservice360.fragments.ContactDetailsFragment;
import biznussoft.fieldservice360.listeners.GlobalListener;

             

public class AccountsActivity extends BaseActivity implements GlobalListener{
	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.master_details_page_activity);
	}  
	 
	public void onCategoryClicked(int position) {
      
		if(position >= 0){                                
			AccountsdetailsFragment newFragment = new AccountsdetailsFragment();
			Bundle args = new Bundle();
			args.putInt("Position", position);
			newFragment.setArguments(args);
			FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
			transaction.replace(R.id.viewer, newFragment);
			transaction.addToBackStack(null);
			transaction.commit();
		}
		if(position == -2)
		{
			finish();
		}

	}

	@Override
	public void onNewContact(String[] args) {
		
		ContactDetailsFragment newFragment = new ContactDetailsFragment();
		Bundle args2 = new Bundle();
		args2.putInt("Position", 0);
		args2.putString("MailingCountry", args[0]);
		args2.putString("MaillingCity", args[1]);
		args2.putString("Maillingstate", args[2]);
		args2.putString("MaillingStreet", args[3]);
		args2.putString("MaillingZip", args[4]);
		args2.putString("Contactphone", args[5]);
		args2.putString("ContactAccountName", args[6]);
		args2.putString("AccountId", args[7]);
		newFragment.setArguments(args2);
		FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
		transaction.replace(R.id.viewer, newFragment);   
		transaction.addToBackStack(null);
		transaction.commit();
	}

	@Override
	public void onGetContacts(final int position,final String category) {
	
		ContactDetailsFragment newFragment = new ContactDetailsFragment();
		FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
		transaction.replace(R.id.viewer, newFragment);
		transaction.addToBackStack(null);
		transaction.commit();
		
		new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
            	ContactDetailsFragment  contactFragment = (ContactDetailsFragment) getSupportFragmentManager().findFragmentById(R.id.viewer);       
                contactFragment.showContacts(position,category);
            }
        }, 1000);
		
	}

	@Override
	public void getSignature(String base64) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void displayFields(int position, String category) {
		// TODO Auto-generated method stub
		
	}


}
